package com.song.controller.user;

import com.song.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@Slf4j
@RestController("user-shop-controller")
@RequestMapping("/user/shop")
public class ShopController {
    private static final String SHOP_STATUS_REDIS_KEY = "SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;
    //获取营业状态
    @GetMapping("/status")
    public Result<String> getStatus() {
        log.info("用户获取营业状态接口");
        //从redis中获取店铺的营业状态 1营业 0打烊
        String status =( String) (redisTemplate.opsForValue().get(SHOP_STATUS_REDIS_KEY));
        if (status == null || status.isEmpty()) return Result.error("店铺状态参数为空");
        if(status.equals("0")) return Result.success("0","打烊");
        return Result.success("1","营业");

    }
}
